package handlers

import (
	"encoding/json"
	"github.com/ThreeDotsLabs/watermill/message"
	"proxy_resource_test/bootstrap/models"
	"proxy_resource_test/bootstrap/server"
)

type IpInfoHandler struct {
	data []models.IpInfo
}

func (h *IpInfoHandler) UnmarshalAndCollect(msg *message.Message) error {
	var items models.IpInfo
	if err := json.Unmarshal(msg.Payload, &items); err != nil {
		return err
	}
	h.data = append(h.data, items)
	return nil
}

// Handle 插入数据
func (h *IpInfoHandler) Handle() error {
	return server.DealIpPool(h.data)
}
